﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class TblBpbkDAO:IData<TblBpbk> 
 	{
		public TblBpbkDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref TblBpbk item, int t) {
			 return connec.ExecuteNonQuery("sp_TblBpbk", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + TblBpbk.c_MaBill, item.MaBill), new SqlParameter("@" + TblBpbk.c_MaLoaiBpbk, item.MaLoaiBpbk),
				 new SqlParameter("@" + TblBpbk.c_TenBpbk, item.TenBpbk), new SqlParameter("@" + TblBpbk.c_MaTrangThai, item.MaTrangThai),
				 new SqlParameter("@" + TblBpbk.c_MaKhachHang, item.MaKhachHang), new SqlParameter("@" + TblBpbk.c_MaDonVi, item.MaDonVi),
				 new SqlParameter("@" + TblBpbk.c_DaXoa, item.DaXoa), new SqlParameter("@" + TblBpbk.c_TrongLuong, item.TrongLuong),
				 new SqlParameter("@" + TblBpbk.c_NgayGoi, item.NgayGoi), new SqlParameter("@" + TblBpbk.c_MaNguoiDung, item.MaNguoiDung),
				 new SqlParameter("@" + TblBpbk.c_DonGia, item.DonGia), new SqlParameter("@" + TblBpbk.c_ThanhTien, item.ThanhTien));
		}

		public override TblBpbk GetItem(IDataReader dr)
		{
			TblBpbk obj = new TblBpbk();
            try {
                obj.MaBill = Convert.ToInt32(dr[TblBpbk.c_MaBill]);
                obj.MaLoaiBpbk = Convert.ToInt32(dr[TblBpbk.c_MaLoaiBpbk]);
                obj.TenBpbk = Convert.ToString(dr[TblBpbk.c_TenBpbk]);
                obj.MaTrangThai = Convert.ToInt32(dr[TblBpbk.c_MaTrangThai]);
                obj.MaKhachHang = Convert.ToInt32(dr[TblBpbk.c_MaKhachHang]);
                obj.MaDonVi = Convert.ToInt32(dr[TblBpbk.c_MaDonVi]);
                obj.DaXoa = Convert.ToBoolean(dr[TblBpbk.c_DaXoa]);
                obj.TrongLuong = Convert.ToDouble(dr[TblBpbk.c_TrongLuong]);
                obj.NgayGoi = Convert.ToDateTime(dr[TblBpbk.c_NgayGoi]);
                obj.MaNguoiDung = Convert.ToInt32(dr[TblBpbk.c_MaNguoiDung]);
                obj.DonGia = Convert.ToDouble(dr[TblBpbk.c_DonGia]);
                obj.ThanhTien = Convert.ToDouble(dr[TblBpbk.c_ThanhTien]);
                obj.TenDonVi = Convert.ToString(dr[TblBpbk.c_TenDonVi]);
                obj.TenKhachHang = Convert.ToString(dr[TblBpbk.c_TenKhachHang]);
                obj.TenLoaiBpbk = Convert.ToString(dr[TblBpbk.c_TenLoaiBpbk]);
                obj.TenTrangThai = Convert.ToString(dr[TblBpbk.c_TenTrangThai]);
            }
            catch { }
			

			return obj;
		}

		public override List<TblBpbk> GetAll()
		{
			return GetAll("sp_GetAllTblBpbk", CommandType.StoredProcedure);
		}

		public override TblBpbk GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.MaBill == Convert.ToInt32(id));
		}
		public override TblBpbk GetItemById(TblBpbk item){
			throw new NotImplementedException();
		}

	}

 }
